#define _CRT_SECURE_NO_WARNINGS 1

#include<iostream>
#include<vector>
#include<unordered_map>

using namespace std;

int subarraySum(vector<int>& nums, int k) {
    unordered_map<int, int> m;
    m[0] = 1;
    int count = 0, pre = 0;
    for (auto x : nums) {
        pre += x;
        if (m.find(pre - k) != m.end())
            count += m[pre - k];
        m[pre]++;
    }
    return count;
}